﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace taobaoSpider
{
    public partial class frmCloseSystem : Form
    {
        int iniTime = Convert.ToInt32(ReadIniFile.IniReadValue("closeTime", "time"))/1000;
        public frmCloseSystem()
        {
            InitializeComponent();
            lblTime.Text = iniTime.ToString();
            timerLabel.Enabled = true;
        }

        private void timerLabel_Tick(object sender, EventArgs e)
        {
            if (iniTime > 0)
            {
                iniTime--;
                lblTime.Text = iniTime.ToString();
            }
            else
            {
                timerLabel.Enabled = false;
                GlobalFun.CloseComputerSystem();
            }
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            GlobalFun.CloseComputerSystem();
        }

        //多线程程序中合适使用这个方法，由于线程间不能调用。
        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmCloseSystem_FormClosing(object sender, FormClosingEventArgs e)
        {
            timerLabel.Enabled = false;
        }

        private void frmCloseSystem_Load(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
        }


        //private void CloseCoumputer()
        //{
        //    this.timer1.Enabled = true;  //关机计时器。
        //    this.timer1.Interval = Convert.ToInt32(ReadIniFile.IniReadValue("closeTime", "time"));
        //    DialogResult dialogResult = MessageBox.Show("采集完成是否要关机？离关机时间初值为:" + (timer1.Interval / 1000).ToString() + "秒", "关机", MessageBoxButtons.YesNo);
        //    if (dialogResult == DialogResult.OK)
        //    {
        //        GlobalFun.CloseComputerSystem();
        //    }
        //    else
        //    {
        //        this.timer1.Enabled = false;
        //    }
        //}
    }
}
